package org.xtremeobjects.domain.person;

import javax.persistence.Embedded;
import javax.persistence.Entity;

import org.xtremeobjects.anotations.JavaBean;
import org.xtremeobjects.anotations.Label;
import org.xtremeobjects.anotations.Property;
import org.xtremeobjects.domain.party.Party;

import com.domainlanguage.time.*;
import com.domainlanguage.timeutil.*;

@Entity
@JavaBean
@Label(value="${self.name}, ${self.sex} (${self.birthDate}) ${self.age}")
public class Person extends Party {

	@Property(name="Sexo", after="name")
	private Sex sex;

	@Embedded
	@Property(name="Data de Nascimento", after="sex")
	private CalendarDate birthDate;

	@Property(name="Vivo", after="birthDate")
	private Boolean alive;


	public void setSex(Sex sex) {
		this.sex = sex;
	}

	public Sex getSex() {
		return sex;
	}

	public Boolean getAlive() {
		return alive;
	}

	public CalendarDate getBirthDate() {
		return birthDate;
	}

	public void setAlive(Boolean alive) {
		this.alive = alive;
	}


	public void setBirthDate(CalendarDate birthDate) {
		this.birthDate = birthDate;
	}

	public Person(String name, Sex sex, CalendarDate birthDate, Boolean alive)
	{
		this.name = name;
		this.sex = sex;
		this.birthDate = birthDate;
		this.alive = alive;
	}


	private Person() {
	}

	@Property(name="Idade")
	public int getAge()
	{
		Clock.setDefaultTimeZone(java.util.TimeZone.getDefault() );
		CalendarInterval interval = CalendarInterval.inclusive(getBirthDate(), Clock.today());
		return interval.lengthInMonthsInt()/12;
	} 

}
